//从服务器主动发送请求
//http.request(options[, callback])

const http = require('http')
const path = require('path')
const fs = require('fs')

//访问本地 基于nodejs图书管理系统restful风格版 /books
let options = {
    hostname: 'localhost',
    port: 3000,
    protocol: "http:",
    path: '/books'
}

let req = http.request(options, (res)=>{
    let info = ''
    res.on('data', (chunk)=>{
        info += chunk
        console.log(info)
    })
    res.on('end', ()=>{
        fs.writeFile(path.join(__dirname, 'local.json'), info, (err)=>{
            console.log("获取图书信息")
        })
    })
})

req.end()